import json

from flask import Flask, jsonify, request

from dao.BaseRepository import BaseRepository

app = Flask(__name__)
db = BaseRepository(collectionname="hsgame_latest")

gamename = "厕所穿越记"

if len(str(gamename)) == 0:
    gamename = input("gamename:")
rs, num, msg = db.search_no_page(query={'name': {'$regex': gamename}})
if num == 0:
    raise FileNotFoundError("未找到游戏")
game = rs[0]
print(game.get("pinyin"))


@app.route('/permission/auth/login', methods=["get", "post"])
def hello_world():
    r = {"result": True, "errorCode": 0, "msg": "",
         "json": {"menusTree": [], "menus": [], "accessToken": "5c4d88917a34ede8e6711f8c60d81aec",
                  "user": {"id": "6ba8c70da65c498ba814a99210186d30", "creatorId": None, "creatorName": None,
                           "createTime": "2019-10-25 18:56:32", "modifierId": None, "modifierName": None,
                           "modifyTime": "2020-03-29 22:19:00", "deleted": 0, "username": "MLJ6Y5BTWPNT",
                           "nickname": None, "mobile": None, "orgId": None, "headUrl": None, "sex": None,
                           "password": "15ba9ec2c0ba3c54a57633db3c29be32", "payPassword": None, "birthday": None,
                           "type": None, "isAdmin": 1, "isFront": 1, "status": 0, "isTry": None, "identity": None,
                           "isUsed": 0, "lastCheckTime": "2020-03-29T14:19:00.000+0000"}}, "redirectUrl": ""}

    return jsonify(r)


@app.route("/hsgame/game/getById", methods=["get", "post"])
def getgameid():
    r = {"result": True, "errorCode": 0, "msg": "",
         "json": {"id": game.get("id"), "deleted": 0, "creatorId": None, "creatorName": None,
                  "createTime": "2019-11-19 14:27:28", "modifierId": None, "modifierName": None,
                  "modifyTime": str(game.get("modifyTime")), "name": game.get("name"), "pinyin": game.get("pinyin"),
                  "pinyinFirst": str(game.get("pinyinFirst")),
                  "newGame": 1, "activeCount": 1, "playCount": 1, "encodeKey": game.get("encodeKey"),
                  "sale": 1, "timeLimit": 0, "timeLimitNotice": "",
                  "headUrl": "",
                  "videoUrl": "",
                  "giftUrl": "",
                  "downloadUrl": "", "downloadPassword": "",
                  "buyUrl": "",
                  "readmeUrl": "", "gameDetailImages": []}, "redirectUrl": ""}
    print(json.dumps(r, ensure_ascii=True))
    return jsonify(r)


@app.route('/upload/autoupdate/client/UpdateConfiguration.json', methods=["get", "post"])
def uploadchecj():
    r = {
        "ClientVersion": 0,
        "IsMust": False,
        "files": [

        ]
    }
    return jsonify(r)

#
# @app.route("/system/systemParam/querySystemParamByCode", methods=["get", "post"])
# def ff():
#     data = request.form
#     code = data.get("code", "")
#     print(code)
#     if code == "gameConfig":
#         r = {"result": True, "errorCode": 0, "msg": "",
#              "json": {"deleted": 0, "creatorId": None, "creatorName": None,
#                       "createTime": "2019-08-07 10:39:46", "modifierId": None, "modifierName": None,
#                       "modifyTime": "2020-03-31 20:40:35", "code": "gameConfig", "name": None,
#                       "param": "",
#                       "isSystem": None}, "redirectUrl": ""}
#     else:
#         r = {"result": True, "errorCode": 0, "msg": "",
#              "json": {"deleted": 0, "creatorId": None, "creatorName": None,
#                       "createTime": "2019-10-12 05:05:38", "modifierId": None, "modifierName": None,
#                       "modifyTime": "2020-03-31 20:48:07", "code": "activity", "name": None, "param": "1111",
#                       "isSystem": None}, "redirectUrl": ""}
#
#     return jsonify(r)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80, debug=True)
